<div class="layui-fluid" id="VIEW-list-table" lay-title="客户查询">
    <div class="layui-row layui-col-space10">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">筛选数据</div>
                <div class="layui-card-body">
                    <form class="layui-form" method="get" lay-filter="lig-queryCustomer-searchform">
                        <div class="layui-form-item" style="margin-bottom:0;">
                            <div class="layui-inline">
                                <label class="layui-form-label">公司</label>
                                <div class="layui-input-inline">
                                    <input type="text" class="layui-input" name="fullName" />
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label" style="width:20px;"></label>
                                <input type="button" class="layui-btn layui-btn-sm" lay-filter="lig-queryCustomer-search" value="&nbsp;查&nbsp;询&nbsp;"></input>
                                    <input type="reset" class="layui-btn layui-btn-sm layui-btn-primary" value=" 重 置 ">
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <div class="layui-card">
                <div class="layui-card-body nepadmin-table-full">
                    <table lay-filter="lig-queryCustomer-table"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="tpl-queryCustomer-table-row-toolBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="lig-detail" title="详情" lay-data="{{d.id}}">详情</a>
</script>

<script type="text/html" id="tpl-queryCustomer-detail">
    <span class="layui-layer-setwin"><a class="layui-layer-ico layui-layer-close layui-layer-close1" href="javascript:;"></a></span>
    <form class="layui-form" style="padding-top: 40px;" lay-filter="lig-saveForm">
        <div class="layui-collapse">
          <div class="layui-colla-item">
            <h2 class="layui-colla-title">基本信息</h2>
            <div class="layui-colla-content layui-show">
                <div class="layui-form-item" style="margin-bottom:0;">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width:70px;">公司：</label>
                        <div class="layui-input-inline" style="width:280px;">
                            <span style="height: 30px; line-height: 30px;color: #999!important;">{{d.name}}</span>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" style="margin-bottom:0;">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width:70px;">区域：</label>
                        <div class="layui-input-inline" style="width:140px;">
                            <span style="height: 30px; line-height: 30px;color: #999!important;">{{d.area}}</span>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width:70px;">行业：</label>
                        <div class="layui-input-inline" style="width:140px;">
                            <span style="height: 30px; line-height: 30px;color: #999!important;">{{d.industry}}</span>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" style="margin-bottom:0;">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width:70px;">法人：</label>
                        <div class="layui-input-inline" style="width:140px;">
                            <span style="height: 30px; line-height: 30px;color: #999!important;">{{d.legal}}</span>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width:70px;">微信：</label>
                        <div class="layui-input-inline" style="width:140px;">
                            <span style="height: 30px; line-height: 30px;color: #999!important;">{{d.wxNumber}}</span>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" style="margin-bottom:0;">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width:70px;">业务员：</label>
                        <div class="layui-input-inline" style="width:140px;">
                            <span style="height: 30px; line-height: 30px;color: #999!important;">{{d.salesName}}</span>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width:70px;">状态：</label>
                        <div class="layui-input-inline" style="width:140px;">
                            <span style="height: 30px; line-height: 30px;color: #999!important;">{{d.statusName}}</span>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" style="margin-bottom:0;">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width:70px;">更新时间：</label>
                        <div class="layui-input-inline" style="width:140px;">
                            <span style="height: 30px; line-height: 30px;color: #999!important;">{{layui.util.toDateString(d.modifiedTime, "yyyy-MM-dd HH:mm:ss") }}</span>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width:70px;">入库时间：</label>
                        <div class="layui-input-inline" style="width:140px;">
                            <span style="height: 30px; line-height: 30px;color: #999!important;">{{layui.util.toDateString(d.createdTime, "yyyy-MM-dd HH:mm:ss") }}</span>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" style="margin-bottom:0;">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width:70px;">电话：</label>
                    </div>
                </div>
                <div class="layui-form-item" style="margin-bottom:0;">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width:50px;"></label>
                        <div class="layui-input-block">
                            <table class="layui-table" lay-skin="line" lay-size="sm" style="border:0;">
                                <colgroup>
                                    <col width="200">
                                    <col width="150">
                                </colgroup>
                                <tbody>
                                    {{# 
                                        layui.each(d.tels, function(i, it){ }}
                                      <tr lay-data="{{it.id}}">
                                        <td>{{ it.telNumber }}</td>
                                        <td style="text-align:right;" class="col-opt">
                                        {{#
                                            if (it.isLegal == 1) {
                                        }}
                                            <span class="layui-badge layui-bg-green">法人电话</span>
                                        {{# } }}
                                        </td>
                                      </tr>
                                    {{#  }); }}
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
          </div>
          <div class="layui-colla-item">
            <h2 class="layui-colla-title">备注</h2>
              <div class="layui-colla-content layui-show" style="padding:0;">
                  <textarea name="remark" class="layui-textarea" disabled style="height:150px;line-height:20px;">{{d.remark}}</textarea>
              </div>
          </div>
          <div class="layui-colla-item">
            <h2 class="layui-colla-title">申贷记录</h2>
            <div class="layui-colla-content layui-show"></div>
          </div>
        </div>
        
    </form>
</script>

<script>
    var choose_user, salesQuantity_dataJson;
    layui.use(['laytpl', 'table', 'form', 'layer', 'element', 'laydate', 'jquery', 'admin', 'lig'], function (laytpl, table, form, layer, element, laydate, $, admin, lig) {
        

        var tableDone = function(res, curr, count) {
            if (res.items && res.items.length > 0) {
                var items = res.items;
                $('div[lay-id="queryCustomerId"]').find('a[lay-event="lig-detail"]').mouseover(function() {
                    var index = $(this).closest('tr').attr('data-index'), it = items[index], id = it.id;
                    lig.ajaxget({
                        url: 'bu/customer/' + id,
                        success: function(result) {
                            laytpl($('#tpl-queryCustomer-detail').html()).render(result.data, function (html) {
                                layer.open({
                                    type: 1,
                                    title: false,
                                    content: html,
                                    closeBtn: 0,
                                    area: ['40%', '100%'],
                                    offset: 'auto',
                                    shadeClose: true,
                                    success: function(layero){
                                        layero.css({'left': 'auto','right': '0'});
                                        element.render('collapse');
                                    }
                                });
                            });
                        }
                    });
                });
            }
        }


        var customerTable;
        var renderTable = function() {
            customerTable = lig.table({
                elem: '[lay-filter="lig-queryCustomer-table"]',
                url: 'bu/queryCustomer/page',
                cols: [[
                    { title: '操作', toolbar: '#tpl-queryCustomer-table-row-toolBar', width: 70},
                    { title: '公司', field: 'name', minWidth: 160 },
                    { title: '法人', field: 'legal', width: 100 },
                    { title: '状态', field: 'statusName', width: 100 },
                    { title: '微信', field: 'wxNumber', width: 60, align: 'center'},
                    { title: '业务员', field: 'salesName', width: 100 },
                    { title: '行业', field: 'industry', width: 140 },
                    { title: '待跟进时间', field: 'statusTime', minWidth: 100, templet: '<div>{{ layui.lig.toDateString(d.followTime, "yyyy-MM-dd") }}</div>', },
                    { title: '状态更改时间', field: 'statusTime', minWidth: 120, templet: '<div>{{ layui.util.toDateString(d.statusTime, "yyyy-MM-dd HH:mm:ss") }}</div>', }
                ]],
                done: function (res, curr, count) {
                    tableDone(res, curr, count);
                    var customerName = $('[lay-filter="lig-queryCustomer-searchform"] input[name="fullName"]').val();
                    if (customerName != '') {
                        var bizData = {customerName: customerName};
                        lig.ajaxpost({
                            url: 'et/event/trigger/save',
                            data: {
                                eventType: 2,
                                eventCode: 'queryCustomer-search',
                                eventName: '搜索客户',
                                bizData: JSON.stringify(bizData)
                            },
                            success: function(res) {
                            }
                        });
                    }
                    
                }
            },{
                mode:'dialog',
                entity: 'queryCustomer',
                primaryField: 'id',
                area: ['50%', 'auto'],
                onDetailOpened: function() {
                    element.render('collapse');
                },
                getUrl: 'bu/customer/{id}'
            });
        }


        form.render();

        renderTable();

    })
</script>